package ipad.asia.controller;

import ipad.asia.dao.ExpressDao;
import ipad.asia.entity.Express;
import ipad.asia.service.ExpressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;


@RestController
public class ExpressController {
    @Autowired
    private ExpressService expressService;
    @Autowired
    private ExpressDao expressDao;

    @RequestMapping("/express/getByOrderId")
    public Express findByOrderId(@RequestParam(value = "orderId") int orderId) {
        return expressDao.findByOrderId(orderId);
    }


    @RequestMapping("/express/getByShopId")
    public List<Express> findByShopId(@RequestParam(value = "shopId") int shopId) {
        return expressService.findByShopId(shopId);
    }

    @RequestMapping("/express/getByConsumerId")
    public List<Express> findByConsumerId(@RequestParam(value = "consumerId") int consumerId) {
        return expressService.findByConsumerId(consumerId);
    }

    @RequestMapping("/express/expressAdd")
    public void expressAdd(@RequestParam(value = "orderId") int orderId,
                           @RequestParam(value = "consumerId") int consumerId,
                           @RequestParam(value = "shopId") int shopId,
                           @RequestParam(value = "expressName",required = false) String expressName,
                           @RequestParam(value = "expressNumber",required = false) String expressNumber,
                           @RequestParam(value = "departAddress",required = false) String departAddress,
                           @RequestParam(value = "destAddress",required = false) String destAddress,
                           @RequestParam(value = "date",required = false) Date date,
                           @RequestParam(value = "statues",required = false)int statues){
        expressService.expressAdd(orderId, consumerId, shopId, expressName, expressNumber, departAddress, destAddress, date,statues);
    }
    @Transactional
    @RequestMapping("/express/updateExpressStatue")
    public void updateExpressStatue(@RequestParam(value = "statues",required = false) int statues,
                                    @RequestParam(value = "id",required = false) int id){
        expressDao.updateExpressStatue(statues, id);
    }
}
